import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err);
};

const Login = () => import("@/views/Login");

const Index = () => import("@/views/Index");
export const routes = [
  {
    path: "/", // 如果路由为/
    redirect: "/login", //重定向到登录组件
  },
  {
    path: "/login",
    name: "登录",
    component: Login,
  },
  {
    path: "/index",
    name: "首页",
    component: Index,
    children: [
      {
        path: "/spaceconfig",
        name: "空间配置",
        component: () => import("@/views/menu/SpaceConfig"),
      },
      {
        path: "/deviceInfo",
        name: "设备信息",
        component: () => import("@/views/menu/DeviceInfo"),
      },
      {
        path: "/ExecutionDevice",
        name: "执行设备",
        component: () => import("@/views/Equipment/ExecutionDevice"),
      },
      {
        path: "/GroupEdit",
        name: "群组编辑",
        component: () => import("@/views/Equipment/GroupEdit"),
      },
      {
        path: "/HostConfig",
        name: "主机配置",
        component: () => import("@/views/Equipment/HostConfig"),
      },
      {
        path: "/InteractiveEdit",
        name: "交互编辑",
        component: () => import("@/views/Equipment/InteractiveEdit"),
      },
      {
        path: "/NetworkConfiguration",
        name: "网络设置",
        component: () =>
          import("@/views/HostConfiguration/NetworkConfiguration"),
      },
      {
        path: "/HostPattern",
        name: "模式",
        component: () => import("@/views/HostConfiguration/HostPattern"),
      },
      {
        path: "/HostMessage",
        name: "信息",
        component: () => import("@/views/HostConfiguration/HostMessage"),
      },
      {
        path: "/NetTopology",
        name: "网络拓扑",
        component: () => import("@/views/menu/NetTopology"),
      },
      {
        path: "/AutomateConfig",
        name: "自动化",
        component: () => import("@/views/Equipment/AutomateConfig"),
      },
      {
        path: "/SceneEdit",
        name: "场景编辑",
        component: () => import("@/views/menu/SceneEdit"),
      },
    ],
  },
];

const router = new VueRouter({
  base: process.env.BASE_URL,
  routes,
});

export default router;
